package com.jiazhong.basic.pack0724;

import lombok.SneakyThrows;

import java.io.File;
import java.io.FileWriter;
import java.io.Writer;
import java.util.Scanner;

public class DemoE {

    @SneakyThrows
    private static void a() {
        File file = new File("/Users/dailyblue/workspace/io/1.txt");
        if (file.isDirectory()) {
            System.out.println("不是一个文件");
            return;
        }
        Writer writer = new FileWriter(file);
        // 写入是写入到了字符缓冲区（临时的内存区域）
        writer.write("你好");
        // 将字符缓冲区中的数据写入到硬盘中
        writer.flush();
        writer.close();
    }

    @SneakyThrows
    private static void b() {
        File file = new File("/Users/dailyblue/workspace/io/1.txt");
        if (file.isDirectory()) {
            System.out.println("不是一个文件");
            return;
        }
        Writer writer = new FileWriter(file);
        Scanner scan = new Scanner(System.in);
        while (true) {
            System.out.print("Input:");
            String input = scan.next();
            if ("再见".equals(input)) {
                break;
            }
            writer.write(input + "\n");
        }
        writer.close();
    }

    // 将D盘下的某个文本文件剪切到E盘中去
    public static void main(String[] args) {
        b();
    }
}
